<template>
  <!-- <div>这是合作伙伴管理</div> -->
  <div class="app-container">
    <el-button type="primary" icon="el-icon-edit">
      添加
    </el-button>
    <el-input v-model="search" placeholder="合作伙伴名称" style="width: 300px;padding-left: 20px" />
    <el-table
      :data="Partner.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
      style="width: 100%"
    >
      <el-table-column
        prop="id"
        label="ID"
        width="80"
      />
      <el-table-column
        prop="name"
        label="合作伙伴名称"
        width="180"
      />
      <el-table-column
        prop="img"
        label="合作伙伴Logo"
        width="600"
      />
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row.id)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  getPartner,
  deletePartner
} from '@/api/partner'

export default {
  data() {
    return {
      Partner: [],
      search: ''
    }
  },
  created() {
    this.loadPartner()
  },
  mounted() {},
  methods: {
    // 获取合作伙伴列表
    loadPartner() {
      getPartner().then(res => {
        console.log(res)
        this.Partner = res.data
      })
    },
    // 删除合作伙伴
    handleDelete: function(id) {
      // console.log('delete')
      this.$confirm('确认删除?', '删除提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 确认执行
        console.log(id)
        new Promise((resolve, reject) => {
          deletePartner({ id: id }).then(res => {
          // 删除成功
            this.loadPartner()
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style>

</style>
